package com.tree.backend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 数据分析Mapper接口
 */
@Mapper
public interface AnalysisMapper extends BaseMapper<Object> {
     /**
      * 获取客户类型分布
      */
     @Select("SELECT customer_type as type, COUNT(*) as count FROM customer " +
             "LEFT JOIN power_zone pz ON pz.id = customer.power_zone_id " +
             "WHERE pz.company_id = #{companyId} " +
             "GROUP BY customer_type")
     List<Map<String, Object>> getCustomerTypeDistribution(@Param("companyId") Integer companyId);
     
     /**
      * 获取需求类型分布
      */
     @Select("SELECT demand_type as type, COUNT(*) as count FROM customer_demand " +
             "WHERE company_id = #{companyId} " +
             "GROUP BY demand_type")
     List<Map<String, Object>> getDemandTypeDistribution(@Param("companyId") Integer companyId);
     
     /**
      * 获取需求状态分布
      */
     @Select("SELECT demand_status as type, COUNT(*) as count FROM customer_demand " +
             "WHERE company_id = #{companyId} " +
             "GROUP BY demand_status")
     List<Map<String, Object>> getDemandStatusDistribution(@Param("companyId") Integer companyId);
     
     /**
      * 获取需求紧急程度分布
      */
     @Select("SELECT urgency_level as type, COUNT(*) as count FROM customer_demand " +
             "WHERE company_id = #{companyId} " +
             "GROUP BY urgency_level")
     List<Map<String, Object>> getUrgencyLevelDistribution(@Param("companyId") Integer companyId);
     
     /**
      * 获取客户状态分布
      */
     @Select("SELECT customer.status as type, COUNT(*) as count FROM customer " +
             "LEFT JOIN power_zone pz ON pz.id = customer.power_zone_id " +
             "WHERE pz.company_id = #{companyId} " +
             "GROUP BY customer.status")
     List<Map<String, Object>> getCustomerStatusDistribution(@Param("companyId") Integer companyId);
     
     /**
      * 获取区域用户数量
      */
     @Select("SELECT pz.zone_name as zoneName, COUNT(*) as count FROM customer " +
             "LEFT JOIN power_zone pz ON pz.id = customer.power_zone_id " +
             "WHERE pz.company_id = #{companyId} " +
             "GROUP BY pz.zone_name")
     List<Map<String, Object>> getZoneUserCount(@Param("companyId") Integer companyId);
     
     /**
      * 获取设备类型分布
      */
     @Select("SELECT equipment_type as equipmentType, COUNT(*) as count FROM power_equipment " +
             "LEFT JOIN power_zone pz ON pz.id = power_equipment.power_zone_id " +
             "WHERE pz.company_id = #{companyId} " +
             "GROUP BY equipment_type")
     List<Map<String, Object>> getEquipmentTypeDistribution(@Param("companyId") Integer companyId);
     
     /**
      * 获取区域总供电
      */
     @Select("SELECT zone_name as zoneName, SUM(total_capacity) as totalCapacity FROM power_zone " +
             "WHERE company_id = #{companyId} " +
             "GROUP BY zone_name")
     List<Map<String, Object>> getZoneCapacity(@Param("companyId") Integer companyId);
}